<!--
 * @Author: your name
 * @Date: 2021-06-26 09:14:35
 * @LastEditTime: 2021-11-25 18:42:59
 * @LastEditors: [you name]
 * @Description: In User Settings Edit
 * @FilePath: \briup-ui\src\pages\owner\index.vue
-->
<template>
  <!-- 个人信息页面 -->
  <div>
    <div>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="" >
          <div class="image"><el-image
            style="width: 100px; height: 100px"
            :src="form.userFace"
            :preview-src-list="[form.userFace]"
          />
          </div>
          <el-button class="but" type="text" @click="changePictrue">修改头像</el-button>
          <br>
        </el-form-item>
        <el-form-item label="登陆用户:">
          <span>{{form.username}}</span>
        </el-form-item>
        <el-form-item label="用户姓名:">
          <span>{{form.realname}}</span>
        </el-form-item>
        <el-form-item label="用户手机:">
          <span>{{form.telephone}}</span>
        </el-form-item>
        <el-form-item label="用户性别:">
          <span>{{form.gender}}</span>
        </el-form-item>
        <el-form-item label="用户角色:">
          <span>{{form.roles[0].name}}</span>
        </el-form-item>
        <el-form-item label="用户生日:">
          <span>{{form.birth}}</span>
        </el-form-item>
        <el-form-item label="注册时间:">
          <span>{{form.certificationTime}}</span>
        </el-form-item>
        <el-form-item label="邮箱:">
          <span>{{form.email}}</span>
        </el-form-item>
        <el-form-item label="用户状态:">
          <span>{{form.status}}</span>
        </el-form-item>
        <el-button type="text" @click="changeMessage">修改个人信息</el-button>
      </el-form>
    </div>
    <!-- 头像弹框 -->
    <div>
      <el-dialog title="修改头像" :visible.sync="dialogVisible">
        <!-- {{ form.userFace }} -->
        <el-image :src="form.userFace"></el-image>
        <el-upload
          class="avatar-uploader"
          :action="uploadFileURL"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-circle-plus-outline" />
        </el-upload>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="sure">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <!-- 修改信息弹框 -->
    <div>
      <el-dialog title="提示" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="登陆用户">
            <el-input v-model="form.username" autocomplete="off" />
          </el-form-item>
        </el-form>
        <el-form :model="form">
          <el-form-item label="姓名">
            <el-input v-model="form.realname" autocomplete="off" />
          </el-form-item>
        </el-form>
        <el-form :model="form">
          <el-form-item label="性别">
            <el-radio v-model="form.gender" label="男">男</el-radio>
            <el-radio v-model="form.gender" label="女">女</el-radio>
          </el-form-item>
        </el-form>
        <el-form :model="form">
          <el-form-item label="用户手机">
            <el-input v-model="form.telephone" autocomplete="off" />
          </el-form-item>
        </el-form>
        <el-form :model="form">
          <el-form-item label="用户邮箱">
            <el-input v-model="form.email" autocomplete="off" />
          </el-form-item>
        </el-form>
        <el-form :model="form">
          <el-form-item label="出生日期">
            <div class="block">
              <span class="demonstration" />
              <el-date-picker
                v-model="form.birth"
                type="date"
                placeholder="选择日期"
              />
            </div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="yes">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { login, getInfo, alterUserface, saveOrUpdate } from '@/api/user'
import { showFileURL, uploadFileURL } from '@/utils/config'
export default {
  data() {
    return {
      showFileURL,
      uploadFileURL,
      imageUrl: '',
      dialogVisible: false,
      dialogFormVisible: false,
      token: '',
      form: {},
      picture: {},
      url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
      srcList: [
        'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
        'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
      ]
    }
  },
  computed: {},
  created() {
    this.getToken()
  },
  mounted() {},
  methods: {
    async getToken() {
      const res = await login({
        password: '123321',
        username: 'admin1'
      })
      this.token = res.data.token
      this.getMessage()
    },
    async getMessage() {
      const res = await getInfo(this.token)
      console.log(res.data)
      this.form = { ...res.data }
      this.imageUrl = form.userFace
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
    changePictrue() {
      this.dialogVisible = true
    },

    async sure() {
      this.dialogVisible = false
      const temp = {
        id: this.form.id,
        userface: this.form.userFace
      }
      const res = await alterUserface(temp)
      console.log(res)
    },
    handleAvatarSuccess(res, file) {
      // console.log(res, "==图片上传成功之后的res");
      this.imageUrl = URL.createObjectURL(file.raw)
      // console.log(this.imageUrl);
      this.form.userFace = showFileURL + res.data.id
    },
    changeMessage() {
      this.dialogFormVisible = true
    },
    async yes() {
      this.dialogFormVisible = false
      const res = await saveOrUpdate(this.form)
      console.log(res)
    }
  }
}
</script>
<style scoped>
    .image{
        position: absolute;
        /* padding-left: 300px; */
        right: 10%;
    }
    .but{
        position: absolute;
        /* padding-left: 300px; */
        right: 5%;
    }
</style>
